<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="转债代码" prop="bondId">
        <el-input
          v-model="queryParams.bondId"
          placeholder="请输入转债代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="转债名称" prop="bondNm">
        <el-input
          v-model="queryParams.bondNm"
          placeholder="请输入转债名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="正股代码" prop="stockId">
        <el-input
          v-model="queryParams.stockId"
          placeholder="请输入正股代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="正股名称" prop="stockNm">
        <el-input
          v-model="queryParams.stockNm"
          placeholder="请输入正股名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['bond:basic:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['bond:basic:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['bond:basic:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['bond:basic:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="basicList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="转债代码" align="center" prop="bondId" />
      <el-table-column label="转债名称" align="center" prop="bondNm" />
      <el-table-column label="代码拼音" align="center" prop="bondPy" />
      <el-table-column label="现价" align="center" prop="price" />
      <el-table-column label="涨跌幅" align="center" prop="increaseRt" />
      <el-table-column label="正股代码" align="center" prop="stockId" />
      <el-table-column label="正股名称" align="center" prop="stockNm" />
      <el-table-column label="正股拼音" align="center" prop="stockPy" />
      <el-table-column label="正股价" align="center" prop="sprice" />
      <el-table-column label="正股涨跌" align="center" prop="sincreaseRt" />
      <el-table-column label="PB" align="center" prop="pb" />
      <el-table-column label="转股价" align="center" prop="convertPrice" />
      <el-table-column label="转股价值" align="center" prop="cValue" />
      <el-table-column label="转股溢价率" align="center" prop="premiumRt" />
      <el-table-column label="双低" align="center" prop="dblow" />
      <el-table-column label="上市日" align="center" prop="listDt" />
      <el-table-column label="评级" align="center" prop="ratingCd" />
      <el-table-column label="回售触发价" align="center" prop="putConvertPrice" />
      <el-table-column label="强赎触发价" align="center" prop="forceRedeemPrice" />
      <el-table-column label="转债流通市值占比" align="center" prop="convertAmtRatio" />
      <el-table-column label="到期时间" align="center" prop="maturityDt" />
      <el-table-column label="剩余年限" align="center" prop="yearLeft" />
      <el-table-column label="剩余规模" align="center" prop="currIssAmt" />
      <el-table-column label="成交额" align="center" prop="volume" />
      <el-table-column label="换手率" align="center" prop="turnoverRt" />
      <el-table-column label="转股起始日" align="center" prop="convertCdTip" />
      <el-table-column label="发行规模" align="center" prop="origIssAmt" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['bond:basic:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['bond:basic:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改可转债基础信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="转债id" prop="bondId">
          <el-input v-model="form.bondId" placeholder="请输入转债id" />
        </el-form-item>
        <el-form-item label="转债名称" prop="bondNm">
          <el-input v-model="form.bondNm" placeholder="请输入转债名称" />
        </el-form-item>
        <el-form-item label="代码拼音" prop="bondPy">
          <el-input v-model="form.bondPy" placeholder="请输入代码拼音" />
        </el-form-item>
        <el-form-item label="现价" prop="price">
          <el-input v-model="form.price" placeholder="请输入现价" />
        </el-form-item>
        <el-form-item label="涨跌幅" prop="increaseRt">
          <el-input v-model="form.increaseRt" placeholder="请输入涨跌幅" />
        </el-form-item>
        <el-form-item label="正股代码" prop="stockId">
          <el-input v-model="form.stockId" placeholder="请输入正股代码" />
        </el-form-item>
        <el-form-item label="正股名称" prop="stockNm">
          <el-input v-model="form.stockNm" placeholder="请输入正股名称" />
        </el-form-item>
        <el-form-item label="正股拼音" prop="stockPy">
          <el-input v-model="form.stockPy" placeholder="请输入正股拼音" />
        </el-form-item>
        <el-form-item label="正股价" prop="sprice">
          <el-input v-model="form.sprice" placeholder="请输入正股价" />
        </el-form-item>
        <el-form-item label="正股涨跌" prop="sincreaseRt">
          <el-input v-model="form.sincreaseRt" placeholder="请输入正股涨跌" />
        </el-form-item>
        <el-form-item label="PB" prop="pb">
          <el-input v-model="form.pb" placeholder="请输入PB" />
        </el-form-item>
        <el-form-item label="转股价" prop="convertPrice">
          <el-input v-model="form.convertPrice" placeholder="请输入转股价" />
        </el-form-item>
        <el-form-item label="转股价值" prop="cValue">
          <el-input v-model="form.cValue" placeholder="请输入转股价值" />
        </el-form-item>
        <el-form-item label="${comment}" prop="convertDt">
          <el-input v-model="form.convertDt" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="转股溢价率" prop="premiumRt">
          <el-input v-model="form.premiumRt" placeholder="请输入转股溢价率" />
        </el-form-item>
        <el-form-item label="双低" prop="dblow">
          <el-input v-model="form.dblow" placeholder="请输入双低" />
        </el-form-item>
        <el-form-item label="${comment}" prop="swCd">
          <el-input v-model="form.swCd" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="marketCd">
          <el-input v-model="form.marketCd" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="上市日" prop="listDt">
          <el-input v-model="form.listDt" placeholder="请输入上市日" />
        </el-form-item>
        <el-form-item label="${comment}" prop="tFlag">
          <el-input v-model="form.tFlag" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="owned">
          <el-input v-model="form.owned" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="hold">
          <el-input v-model="form.hold" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="bondValue">
          <el-input v-model="form.bondValue" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="评级" prop="ratingCd">
          <el-input v-model="form.ratingCd" placeholder="请输入评级" />
        </el-form-item>
        <el-form-item label="${comment}" prop="optionValue">
          <el-input v-model="form.optionValue" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="回售触发价" prop="putConvertPrice">
          <el-input v-model="form.putConvertPrice" placeholder="请输入回售触发价" />
        </el-form-item>
        <el-form-item label="强赎触发价" prop="forceRedeemPrice">
          <el-input v-model="form.forceRedeemPrice" placeholder="请输入强赎触发价" />
        </el-form-item>
        <el-form-item label="转债流通市值占比" prop="convertAmtRatio">
          <el-input v-model="form.convertAmtRatio" placeholder="请输入转债流通市值占比" />
        </el-form-item>
        <el-form-item label="${comment}" prop="fundRt">
          <el-input v-model="form.fundRt" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="到期时间" prop="maturityDt">
          <el-input v-model="form.maturityDt" placeholder="请输入到期时间" />
        </el-form-item>
        <el-form-item label="剩余年限" prop="yearLeft">
          <el-input v-model="form.yearLeft" placeholder="请输入剩余年限" />
        </el-form-item>
        <el-form-item label="剩余规模" prop="currIssAmt">
          <el-input v-model="form.currIssAmt" placeholder="请输入剩余规模" />
        </el-form-item>
        <el-form-item label="成交额" prop="volume">
          <el-input v-model="form.volume" placeholder="请输入成交额" />
        </el-form-item>
        <el-form-item label="${comment}" prop="svolume">
          <el-input v-model="form.svolume" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="换手率" prop="turnoverRt">
          <el-input v-model="form.turnoverRt" placeholder="请输入换手率" />
        </el-form-item>
        <el-form-item label="${comment}" prop="ytmRt">
          <el-input v-model="form.ytmRt" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="putYtmRt">
          <el-input v-model="form.putYtmRt" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="noted">
          <el-input v-model="form.noted" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="lastTime">
          <el-input v-model="form.lastTime" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="sqflag">
          <el-input v-model="form.sqflag" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="pbFlag">
          <el-input v-model="form.pbFlag" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="adjCnt">
          <el-input v-model="form.adjCnt" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="adjScnt">
          <el-input v-model="form.adjScnt" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="convertPriceValid">
          <el-input v-model="form.convertPriceValid" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="convertPriceTips">
          <el-input v-model="form.convertPriceTips" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="转股起始日" prop="convertCdTip">
          <el-input v-model="form.convertCdTip" placeholder="请输入转股起始日" />
        </el-form-item>
        <el-form-item label="${comment}" prop="refldInfo">
          <el-input v-model="form.refldInfo" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="adjusted">
          <el-input v-model="form.adjusted" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="发行规模" prop="origIssAmt">
          <el-input v-model="form.origIssAmt" placeholder="请输入发行规模" />
        </el-form-item>
        <el-form-item label="${comment}" prop="priceTips">
          <el-input v-model="form.priceTips" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="redeemDt">
          <el-input v-model="form.redeemDt" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="realForceRedeemPrice">
          <el-input v-model="form.realForceRedeemPrice" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="optionTip">
          <el-input v-model="form.optionTip" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="afterNextPutDt">
          <el-input v-model="form.afterNextPutDt" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="icoisMinPrice">
          <el-input v-model="form.icoisMinPrice" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="blocked">
          <el-input v-model="form.blocked" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="putting">
          <el-input v-model="form.putting" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="notes">
          <el-input v-model="form.notes" placeholder="请输入${comment}" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listBasic, getBasic, delBasic, addBasic, updateBasic } from "@/api/bond/basic";

export default {
  name: "Basic",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 可转债基础信息表格数据
      basicList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        bondNm: null,
        bondPy: null,
        price: null,
        increaseRt: null,
        stockId: null,
        stockNm: null,
        stockPy: null,
        sprice: null,
        sincreaseRt: null,
        pb: null,
        convertPrice: null,
        cValue: null,
        premiumRt: null,
        dblow: null,
        listDt: null,
        ratingCd: null,
        putConvertPrice: null,
        forceRedeemPrice: null,
        convertAmtRatio: null,
        maturityDt: null,
        yearLeft: null,
        currIssAmt: null,
        volume: null,
        turnoverRt: null,
        convertCdTip: null,
        origIssAmt: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        bondId: [
          { required: true, message: "转债id不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询可转债基础信息列表 */
    getList() {
      this.loading = true;
      listBasic(this.queryParams).then(response => {
        this.basicList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        bondId: null,
        bondNm: null,
        bondPy: null,
        price: null,
        increaseRt: null,
        stockId: null,
        stockNm: null,
        stockPy: null,
        sprice: null,
        sincreaseRt: null,
        pb: null,
        convertPrice: null,
        cValue: null,
        convertDt: null,
        premiumRt: null,
        dblow: null,
        swCd: null,
        marketCd: null,
        btype: null,
        listDt: null,
        tFlag: null,
        owned: null,
        hold: null,
        bondValue: null,
        ratingCd: null,
        optionValue: null,
        putConvertPrice: null,
        forceRedeemPrice: null,
        convertAmtRatio: null,
        fundRt: null,
        maturityDt: null,
        yearLeft: null,
        currIssAmt: null,
        volume: null,
        svolume: null,
        turnoverRt: null,
        ytmRt: null,
        putYtmRt: null,
        noted: null,
        lastTime: null,
        qstatus: null,
        sqflag: null,
        pbFlag: null,
        adjCnt: null,
        adjScnt: null,
        convertPriceValid: null,
        convertPriceTips: null,
        convertCdTip: null,
        refldInfo: null,
        adjusted: null,
        origIssAmt: null,
        priceTips: null,
        redeemDt: null,
        realForceRedeemPrice: null,
        optionTip: null,
        afterNextPutDt: null,
        icoisMinPrice: null,
        blocked: null,
        putting: null,
        notes: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加可转债基础信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getBasic(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改可转债基础信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateBasic(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBasic(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除可转债基础信息编号为"' + ids + '"的数据项？').then(function() {
        return delBasic(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('bond/basic/export', {
        ...this.queryParams
      }, `basic_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
